<template>
	<view class="container">
		<!--header-->
		<view class="search-header-box">
			<view class="search-header">
				<view class="search-searchbox">
					<view class="iconfont iconsousuohome" @tap="getProductList({size:15,num:1})"></view>
					<input class="search-input" v-model="searchKey" confirm-type="search" placeholder="请输入商品信息"
					@confirm="getProductList({size:15,num:1})"></input>
					<!-- <view class="search-clear iconfont iconguanbi1" v-if="searchKey"
					@tap="searchKeyFun"></view> -->
				</view>
				<view class="dateClass" @tap="showFun()">
					<image class="dateImg" src="../../../static/img/date.png" mode=""></image>
				</view>
			</view>
			<view class="rukuButton">
				<view class="stockGoodsOutType">
					<picker @change="stockGoodsOutTypeChange" :value="stockGoodsOutTypeIndex" :range="stockGoodsOutTypeList">
						<view class="refundInfo">
							<view class="setupCon">
								<text class="" v-if="stockGoodsOutTypeLable">{{ stockGoodsOutTypeLable }}</text>
								<text class="iconfont iconxiangxia1"></text>
							</view>
						</view>
					</picker>
				</view>
				
			</view>
		</view>
		
		<view class="productList-wrap">
		<!-- 产品列表 -->
		<mescroll-body
			ref="mescrollRef" 
			@init="mescrollInit" 
			@down="downCallback"
			:up="upOption" 
			@up="getProductList"
			:fixed="true"
			top='170rpx'
			bottom='150rpx'
		>
			<view class="securityInfo">
				<view class="stockLess" v-for="(item,index) in safeStockList" :key='index' @tap='goDetail(item)'>
					<view class="stockLeft">
						{{item.goodsName}}<span style='margin-left: 20rpx;'>{{item.goodsMatcode}}</span>
					</view>
					<view class="stockRight">
						<span class='fStockNum'>{{item.count}}</span>个
					</view>
					
				</view>
				<view class="sum-number" v-if="safeStockList.length>0">
					总计：<span class='number'>{{totalcount}}个</span>
				</view>
			</view>
		</mescroll-body>
		</view>
		<!-- <loading></loading> -->
		<view class="bot-btn-wrap fix-bot bg-none">
			<picker @change="outTypeChange" :value="outTypeIndex" :range="outTypeList">
				<!-- <mix-button ref="confirmBtn" text="出库" icon="icon-jia2" :iconSize="36" :isConfirm="false"></mix-button> -->
				<view  class="mix-btn-content" >
					<text class="mix-text">出库</text>
				</view>
			</picker>
		</view>
		<!-- <button type="default" @tap='goWarehousing'>入库</button> -->
		<tui-modal></tui-modal>
		<date-popup @determine='determine' :beginDate='beginDate' :endDate='endDate' :popupShow='popupShow' @colosePopup='colosePopup'></date-popup>
	</view>
</template>

<script>
	import mixin from "@/utils/mixin.js"
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import datePopup from "@/components/datePopup/index.vue"
	import mixButton from '@/components/mix-button/mix-button.vue';
	export default {
		mixins:[mixin,MescrollMixin],
		components: {
			datePopup,
			mixButton
		},
		
		data() {
			return {
				searchKey: "", //搜索关键词
				safeStockList:[],
				upOption:{
					auto: false, // 不自动加载
					page: {
					 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					 	size: 15 // 每页数据的数量
					},
					noMoreSize: 15, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
				},
				beginDate:'',
				endDate:'',
				popupShow:false,
				stockGoodsOutTypeLable:'全部',
				stockGoodsOutTypeIndex:0,
				stockGoodsOutTypeList:['全部','销售出库','线下出库','返厂出库','过期出库'],
				outTypeIndex:0,
				outTypeList:['线下出库','返厂出库','过期出库'],
				totalcount:0
			}
		},
		onLoad(options) {
			// #ifdef H5
			   this.$wechat.noShare();
			// #endif
			if(options.searchText){
				this.searchKey=options.searchText
			}
			if(options.beginDate){
				this.beginDate=options.beginDate
			}
			if(options.endDate){
				this.endDate=options.endDate
			}
		},
		mounted() {
			// 监听页面刷新
			this.$eventHub.$off('reduceStockList');
			this.$eventHub.$on('reduceStockList', () => {
			  this.mescroll.resetUpScroll();
			});
		},
		methods: {
			determine(data,flag){
				if(flag=='clear'){
					this.beginDate=''
					this.endDate=''
				}else{
					this.beginDate=data[0]
					this.endDate=data[1]
				}
				this.popupShow=false
				console.log(data)
				console.log(this.beginDate)
				console.log(this.endDate)
				this.getProductList({size:15,num:1})
			},
			showFun(){
				this.popupShow=true
				console.log(this.popupShow)
			},
			colosePopup(){
				this.popupShow=false
			},
			stockGoodsOutTypeChange(e){
					this.stockGoodsOutTypeIndex = e.target.value;
					this.stockGoodsOutTypeLable = this.stockGoodsOutTypeList[this.stockGoodsOutTypeIndex];
					this.getProductList({size:15,num:1})
				
			},
			outTypeChange(e){
					this.outTypeIndex = e.target.value;
					this.outTypeLable = this.outTypeList[this.outTypeIndex];
					this.goWarehousing()
				
			},
			//商品列表
			getProductList(page) {
				let typeIndex=''
				if(this.stockGoodsOutTypeIndex==0){
					typeIndex=''
				}else{
					typeIndex=Number(this.stockGoodsOutTypeIndex)
				}
				let params={
					current:page.num,
					pageSize:page.size,
					beginDate:this.beginDate,
					endDate:this.endDate,
					searchText:this.searchKey,
					stockGoodsOutType:typeIndex
				};
				this.$http.outRecord(params).then((res) => {
					if (res.status === 0) {
						if(res.data.records.length>0){
							this.totalcount=res.data.records[0].totalcount
						}else{
							this.totalcount=0
						}
						let curPageData =res.data.records;
						this.mescroll.endSuccess(res.data.records.length);
						if (page.num == 1) {
							this.safeStockList = []
						};
						this.safeStockList = this.safeStockList.concat(curPageData);
						console.log(this.safeStockList)
					}
				}).catch(() => {
					this.mescroll.endErr()
				});
			},
			
			recordsIcon(){
				this.recordsList=[]
			},
			//搜索框输入
			searchKeyFun(){
				this.searchKey=''
			},
			goWarehousing(){
				let type=Number(this.outTypeIndex)+2
				uni.navigateTo({
					url:'./deliveryStockOk?type='+type
				})
			},
			goDetail(item){
				uni.navigateTo({
					url:'./deliveryStockDetail?goodsId='+item.goodsId+'&goodsMatcode='+item.goodsMatcode
				})
			},
		},
	}
</script>

<style lang="scss">
	.container {
		background: #fff;
		min-height: 100vh;
	}
	.bot-btn-wrap{
		background-color: #fff;
	}
	.bot-btn-wrap {
	    position: fixed;
	    left: 0;
	    bottom: 0;
	    bottom: 0;
	    z-index: 90;
	    width: 100%;
	    padding: 20rpx 0;
	    background-color: #fff;
	    border-top: 2rpx solid #eee;
	}
	.productList-wrap{
		margin-bottom:128rpx;
	}
	.stockGoodsOutType{
		width: 250rpx;
		background-color: #EEEEEE;
		// text-align: center;
		margin-left: 20rpx;
		border-radius: 20rpx;
		float: right;
		padding: 5rpx 0;
		font-size: 28rpx;
		color: #333;
		
		.setupCon{
			display: flex;
			justify-content: space-between;
			padding: 5rpx 20rpx;
			align-items: center;
		}
		
	}
	/* 隐藏scroll-view滚动条*/
	::-webkit-scrollbar {
		width: 0;
		height: 0;
		color: transparent;
	}
	.search-header-box {
		width: 100%;
		height: 170rpx;
		background: #fff;
		position: fixed;
		z-index: 99991;
		left: 0;
		top: 0;
		
		.rukuButton{
			padding: 10rpx 40rpx;
			border-top: 15rpx solid $borderColor;
			.rukuBtn{
				width: 100rpx;
				background: linear-gradient(151deg, #F69E97 0%, #EA655E 100%);
				text-align: center;
				border-radius: 20rpx;
				float: right;
				padding: 5rpx 0;
				margin-top: 15rpx;
				font-size: 28rpx;
				color: #fff;
			}
		}
		
	}
	.search-header {
		display: flex;
		align-items: center;
		padding: 0 20rpx;
		margin-bottom: 10rpx;
	}
	.search-searchbox {
		flex: 1;
		height: 70rpx;
		border-radius: 80rpx;
		font-size: 24rpx;
		// background: $borderColor;
		border:2rpx solid $themeColor1;
		padding: 6rpx 20rpx;
		box-sizing: border-box;
		color: #999;
		display: flex;
		align-items: center;
		overflow: hidden;
	}
	.dateClass{
		width: 50rpx;
		height: 50rpx;
		margin-left: 40rpx;
		
		.dateImg{
			width: 100%;
			height: 100%;
		}
	}
	.search-input {
		text-align: left !important;
		margin-left: 12rpx;
		width: 100% !important;
		background-color: #fff !important;
		color:#121212;
		font-size: 28rpx;
		.uni-input-input {
			width: 100%;
			font-size: 30rpx;
		}
	}
	
	.search-text {
		font-size: 32rpx;
		color: #444;
		margin: 0 20rpx 0 30rpx;
		color: $red;
	}
	.search-search-text {
		padding-left: 16rpx;
	}
	.search-search-key {
		max-width: 80%;
		height: 100%;
		padding: 0 16rpx;
		margin-left: 12rpx;
		display: flex;
		align-items: center;
		border-radius: 15px;
		background: rgba(0, 0, 0, 0.5);
		color: #fff;
	}
	.search-key-text {
		box-sizing: border-box;
		padding-right: 12rpx;
		font-size: 12px;
		line-height: 12px;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	.search-clear{
		padding:10rpx;
	}
	
	.securityInfo{
		padding: 0rpx 25rpx;
		margin-top: 10rpx;
		background-color: #fff;
		padding-bottom: 40rpx;
		.stockLess{
			padding: 15rpx 0;
			display: flex;
			justify-content:space-between;
			align-items: center;
			.stockLeft{
				width: 450rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				font-size: 32rpx;
				color: #111111;
			}
			.stockRight{
				font-size: 28rpx;
				color: #111111;
				.fStockNum{
					color: #EA655E;
				}
			}
			
		}
		.sum-number{
			width: 100%;
			padding: 20rpx 0;
			border-top: 2rp solid #f7f7f7;
			display:flex;
			 justify-content: flex-end;
			align-items: center;
			.number{
				margin-left: 10rpx;
				color: #EA655E;
			}
		}
		
	}
	.mix-btn-content{
		display: flex;
		align-items: center;
		justify-content: center;
		width: 50%;
		height: 60rpx;
		margin: 0 auto;
		font-size: 32rpx;
		color: #fff;
		border-radius: 100rpx;
		background: linear-gradient(151deg, #F69E97 0%, #EA655E 100%);
		box-shadow: 0px 4rpx 20rpx 0px rgba(83, 0, 0, 0.24);
		position: relative;
		
		&:after{
			content: '';
			position: absolute;
			left: 50%;
			top: 25%;
			transform: translateX(-50%);
			width: 85%;
			height: 85%;
			/* background: linear-gradient(131deg, rgba(255,115,138,1) 0%, rgba(255,83,111,1) 100%); */
			
			border-radius: 100rpx;
			opacity: 0.4;
			filter:blur(10rpx);
		}
		&.disabled {
			opacity: .65;
		}
		.mix-text{
			position: relative;
			z-index: 1;
		}
		.mix-icon{
			position: relative;
			z-index: 1;
			margin-right: 8rpx;
		}
		.loading-icon{
			width: 34rpx;
			height: 34rpx;
			transform-origin:50% 50%;
			margin-right: 16rpx;
			animation: rotate 2s linear infinite;
			position: relative;
			z-index: 1;
		}
	}
</style>
